using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Collections.Generic;
namespace FeedAntGame
{
#if WINDOWS || XBOX
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {

            using (GameFA game =new GameFA())
            {
                Process[] processlist = Process.GetProcesses();
                Process currentProcess = Process.GetCurrentProcess();
                List<Process> sameProcess = new List<Process>();
                int ready = 0;
                foreach(Process theprocess in processlist)
                {
                    if (currentProcess.ProcessName.Equals(theprocess.ProcessName))
                    {
                        sameProcess.Add(theprocess);
                        ready++;
                    }
                }
                if (ready==1)
                {
                    try
                    {
                        game.Run();
                    }
                    catch (System.Exception ex)
                    {
                    	
                    }
                }
                else
                {
                    foreach (Process p in sameProcess)
                    {
                        IntPtr hWnd = p.MainWindowHandle;
                        ShowWindow(hWnd, SW_SHOW);
                    }
                }
            }
        }

        [DllImport("user32.dll")]
        public static extern Boolean ShowWindow(IntPtr hWnd, UInt32 nCmdShow);
        //Definitions For Different Window Placement Constants
        const UInt32 SW_HIDE = 0;
        const UInt32 SW_SHOWNORMAL = 1;
        const UInt32 SW_NORMAL = 1;
        const UInt32 SW_SHOWMINIMIZED = 2;
        const UInt32 SW_SHOWMAXIMIZED = 3;
        const UInt32 SW_MAXIMIZE = 3;
        const UInt32 SW_SHOWNOACTIVATE = 4;
        const UInt32 SW_SHOW = 5;
        const UInt32 SW_MINIMIZE = 6;
        const UInt32 SW_SHOWMINNOACTIVE = 7;
        const UInt32 SW_SHOWNA = 8;
        const UInt32 SW_RESTORE = 9;
    }
#endif
}

